home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * Copyright (c) 1993 Silicon Graphics, Inc.
- * All Rights Reserved
- *
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
- *
- * The copyright notice above does not evidence any actual of intended
- * publication of such source code, and is an unpublished work by Silicon
- * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
- * the property of Silicon Graphics, Inc. Any use, duplication or
- * disclosure not specifically authorized by Silicon Graphics is strictly
- * prohibited.
- *
- * RESTRICTED RIGHTS LEGEND:
- *
- * Use, duplication or disclosure by the Government is subject to
- * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 52.227-7013,
- * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
- * Supplement. Unpublished - rights reserved under the Copyright Laws of
- * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
- * Shoreline Blvd., Mountain View, CA 94039-7311
- **************************************************************************
- *
- * File: imp.h
- *
- * Description: Primary include file for libimp, the SGI Image file format
- * API library. The library is a replacement for and is based upon
- * libimage by Paul Haeberli. One of the intents of libim is to
- * provide a documented, consistent, name space secure, ANSI
- * compatible API to the SGI Image file format.
- *
- **************************************************************************/
-
-
- #ident "$Revision: 1.9 $"
-
-
- #ifndef __IMP_IMP_H__
- #define __IMP_IMP_H__
-
-
- #include <sys/types.h>
-
-
- /* Error codes */
- /* These error codes start well above the error codes defined in
- errno.h. This way we can return errno error codes and libim
- error codes.
- */
- #define IMP_ERR_BASE 500
-
- #define IMP_ERR_READWRITE IMP_ERR_BASE
- #define IMP_ERR_MEMALLOC (IMP_ERR_BASE + 1)
- #define IMP_ERR_BADMAGIC (IMP_ERR_BASE + 2)
- #define IMP_ERR_BADRASTER (IMP_ERR_BASE + 3)
- #define IMP_ERR_BADIMAGE (IMP_ERR_BASE + 4)
- #define IMP_ERR_BADROW (IMP_ERR_BASE + 5)
- #define IMP_ERR_BADDIM (IMP_ERR_BASE + 6)
- #define IMP_ERR_READFLAG (IMP_ERR_BASE + 7)
- #define IMP_ERR_BADBPP (IMP_ERR_BASE + 8)
- #define IMP_ERR_WRITEFLAG (IMP_ERR_BASE + 9)
- #define IMP_ERR_READROW (IMP_ERR_BASE + 10)
- #define IMP_ERR_SHORTREAD (IMP_ERR_BASE + 11)
- #define IMP_ERR_SHORTWRITE (IMP_ERR_BASE + 12)
- #define IMP_ERR_BADFD (IMP_ERR_BASE + 13)
- #define IMP_ERR_SEEK (IMP_ERR_BASE + 14)
- #define IMP_ERR_NOWRITE (IMP_ERR_BASE + 15)
- #define IMP_ERR_NO_TAG (IMP_ERR_BASE + 16)
-
-
- /* Image header constants */
-
- /* Magic number (imagic field) */
- #define IMP_MAGIC 0732 /* Magic number */
-
- /* Name string (name field) */
- #define IMP_NAME_MAX 79
-
- /* Raster type (type field) */
- #define IMP_RASTER_ENC_MASK 0xff00 /* Raster encoding mask */
- #define IMP_RASTER_ENC_VERBATIM 0x0000
- #define IMP_RASTER_ENC_RLE 0x0100
-
- #define IMP_RASTER_BPP_MASK 0x00ff /* Bytes per pixel mask */
- #define IMP_RASTER_BPP1 0x0001
- #define IMP_RASTER_BPP2 0x0002
- /* Combined codes */
- #define IMP_RASTER_VERBATIM1 (IMP_RASTER_ENC_VERBATIM | IMP_RASTER_BPP1)
- #define IMP_RASTER_VERBATIM2 (IMP_RASTER_ENC_VERBATIM | IMP_RASTER_BPP2)
- #define IMP_RASTER_RLE1 (IMP_RASTER_ENC_RLE | IMP_RASTER_BPP1)
- #define IMP_RASTER_RLE2 (IMP_RASTER_ENC_RLE | IMP_RASTER_BPP2)
-
- /* Image type (colormap field) */
- #define IMP_IMAGE_NORMAL 0 /* Rows are rgb or greyscale values */
- #define IMP_IMAGE_DITHERED 1 /* Obsolete format */
- #define IMP_IMAGE_SCREEN 2 /* Rows are indices for writepixels */
- #define IMP_IMAGE_COLORMAP 3 /* File is a colormap */
-
- /* Extension Tag identifiers */
- #define IMP_TAG_PTR_OFFSET 508
- #define IMP_TAG_LAST_TAG 0
- #define IMP_TAG_FIRST_TAG 1
- #define IMP_TAG_ICC_TAG 2
-
-
- /* Image header macros */
-
- #define impMagic(img) ((img)->imagic)
- #define impRasterType(img) ((img)->type)
- #define impRasterEncoding(img) (((img)->type) & IMP_RASTER_ENC_MASK)
- #define impRasterBPP(img) (((img)->type) & IMP_RASTER_BPP_MASK)
- #define impDimension(img) ((img)->dim)
- #define impXSize(img) ((img)->xsize)
- #define impYSize(img) ((img)->ysize)
- #define impNumChannels(img) ((img)->zsize)
- #define impMinValue(img) ((img)->min)
- #define impMaxValue(img) ((img)->max)
- #define impName(img) ((img)->name)
- #define impImageType(img) ((img)->colormap)
- #define impTags(img) ((img)->tags)
-
- #define impIsRLE(img) (impRasterEncoding(img) == IMP_RASTER_ENC_RLE)
- #define impIsVERBATIM(img) (impRasterEncoding(img) == IMP_RASTER_ENC_VERBATIM)
- #define impMakeRasterType(enc,bpp) (((enc) & IMP_RASTER_ENC_MASK) | \
- ((bpp) & IMP_RASTER_BPP_MASK))
- #define impHasTags(img) (impTags(img) != NULL)
-
-
- /* Enums for image caching */
-
- typedef enum _impCacheMode {
- _IMPBufDirect = -1,
- IMPNoCache = 0,
- IMPHeapCache = 1,
- IMPMapCache = 2
- } IMPCacheMode;
-
-
- /* Enums for zoom filter types */
-
- typedef enum _impFilterType {
- IMPReplicate = 0,
- IMPImpulse = 0,
- IMPBox = 1,
- IMPTriangle = 2,
- IMPQuadratic = 3,
- IMPMitchell = 4,
- IMPGaussian = 5
- } IMPFilterType;
-
-
- /* Function types for device CMYK functions */
-
- typedef short (*IMPBGFunc)(short k);
- typedef short (*IMPUCRFunc)(short k);
-
- /* Function type for routines that need a row read pointer */
-
- typedef int (*IMPReadRowFunc)(short *buffer, ushort_t row, void *clientData);
-
- typedef struct _IMPTagHeader{
- __uint32_t tagname;
- __uint32_t length;
- } IMPTagHeader;
-
- typedef struct _IMPTag{
- IMPTagHeader header;
- struct _IMPTag *next;
- void *data;
- } IMPTag;
-
-
- /* SGI Image file header structure */
- /* This is the header structure for SGI Image format files.
- The names of the structure fields are identical to those
- used in libimage. While libimage based programs reference
- the fields directly, libimip based programs should use the
- image header macros.
- */
-
- typedef struct _impImage {
- /* Public image header information (archived) */
- unsigned short imagic; /* SGI Image file magic number */
- unsigned short type; /* Raster type (e.g. verbatim, rle) */
- unsigned short dim; /* Image dimension */
- unsigned short xsize; /* X size (pixels) */
- unsigned short ysize; /* Y size (pixels) */
- unsigned short zsize; /* Number of channels (e.g. rgb = 3) */
- __int32_t min; /* Minimum intensity in image */
- __int32_t max; /* Maximum intensity in image */
- __uint32_t wastebytes;
- char name[IMP_NAME_MAX+1]; /* Image name */
- __uint32_t colormap; /* Image type (e.g. colormap, normal) */
-
- /* Private image header information (core use only) */
- __int32_t file; /* Image file descriptor */
- unsigned short flags; /* Read/write flag */
- short dorev; /* 1 = need byte swap, 0 = no swap */
- short x; /* x, y and channel of last row seek */
- short y;
- short z;
- short cnt;
- short *ptr;
- short *base;
- short *tmpbuf; /* RLE row temporary storage */
- __uint32_t offset; /* Absolute file position */
- __uint32_t rleend; /* RLE row end relative to start */
- __uint32_t *rowstart; /* RLE row location offset table */
- __int32_t *rowsize; /* RLE row size table */
- /* Private extensions */
- off_t start; /* File position where image starts */
- IMPCacheMode cache; /* Image caching mode */
- void* cachebuf; /* Image cache buffer */
- __uint32_t cachesize; /* Image cache buffer size */
- off_t cacheoffset; /* Absolute cache position */
- IMPTag *tags; /* pointer to first tag */
- } IMPImage;
-
-
- /* Filter shape structure */
- /*
- Y
- |
- areaTab[i] ***********
- \ ** | **
- **** | **
- ***** | *
- _________*|*|*|_|_|_|_|_|_|_|_|*_____ X
-
- | |<-radius->|
- | i |
- minX maxX
- */
-
- typedef struct _impFilterShape {
- float radius; /* Half the width of the filter */
- float minX, maxX; /* X locations at +-radius */
- float *areaTable; /* Total area under curve at const X incrs */
- } IMPFilterShape;
-
-
- /* Filter structure */
-
- typedef struct _impFilter {
- int width; /* Number of pixels or rows of source image
- spanned by filter */
- int totalWeight; /* Sum of all weighting factors in span */
- int halfTotalWeight; /* Half totalWeight */
- short *weight; /* Wieghting factor for each pixel of row */
- short *data; /* Pointer to source pixel or row where
- filter starts */
- } IMPFilter;
-
-
- /* Zoom structure */
-
- typedef struct _impZoom {
- /* General zoom information */
- IMPReadRowFunc readRowFunc; /* Function to read row data */
- int (*zoomRowFunc)(struct _impZoom*, short*, ushort_t, void*);
- ushort_t srcXSize, srcYSize; /* Original image size */
- ushort_t dstXSize, dstYSize; /* New image size */
- IMPFilterType filterType; /* Type of filter to use in zoom */
- short *srcRowBuf; /* Storage for one source row */
- short *dstRowBuf; /* Storage for one zoomed row */
- int numChannels; /* Number of packed channels per row */
-
- /* Impulse (i.e. non-filtered) zoom information */
- short **xMap; /* Maps dst pixel back to src pixel */
- int currentSrcRow; /* Row number of last read source row */
-
- /* Filtered zoom information */
- float blurFactor; /* Blurring (ie. filter width factor) */
- int needClamp; /* 1 = clamp output, 0 = no clamping needed */
- IMPFilterShape *filterShape; /* Filter shape area and info */
- IMPFilter *xFilter; /* Pixel filter array. One fltr per dst pixel */
- IMPFilter *yFilter; /* Row filter array. One filter per dst row */
- /* Filtered row cache */
- int maxFilterRows; /* Max number of rows spanned by vert filter */
- int curFilterRows; /* Current number of cached filter rows */
- int **filterRows; /* Rows spanned by vertical filter */
- int *accumBuf; /* Integer size calculationr temp buffer */
- int currentRowMax; /* Last source image row read */
- long min, max; /* Minimum and maximum intensity */
- /* values; used for clamping */
- } IMPZoom;
-
-
- /* Public global variables */
-
- extern int IMPerrno; /* Error variable */
-
-
- /* Public function declarations */
-
- #ifdef __cplusplus
- extern "C" {
- #endif
- /* Basic functions */
- extern IMPImage* impOpen(const char *fname, const char *mode, ...);
- extern IMPImage* impOpenFd(int fd, const char *mode, ...);
- extern IMPImage* impOpenBuf(void *buf, const char *mode, ...);
- extern IMPImage* impOpenExt(const char *filename, const char *mode,
- off_t offset, IMPCacheMode cache, ...);
- extern IMPImage* impOpenFdExt(int fd, const char *mode, off_t offset,
- IMPCacheMode cache, ...);
- extern IMPImage* impOpenBufExt(void *buf, const char *mode, off_t offset, ...);
- extern int impClose(IMPImage *image);
- extern int impCloseFd(IMPImage *image, int *fdp);
- extern int impWriteRow(IMPImage *image, short *buffer,
- ushort_t row, ushort_t channel);
- extern int impWriteRowB(IMPImage *image, uchar_t *buffer,
- ushort_t row, ushort_t channel);
- extern int impReadRow(IMPImage *image, short *buffer,
- ushort_t row, ushort_t channel);
- extern int impReadRowB(IMPImage *image, uchar_t *buffer,
- ushort_t row, ushort_t channel);
- extern void impPerror(const char *str);
- extern char* impErrorString(int errCode);
- extern int impReadTag(IMPImage *image, uint_t tagname, void **buffer);
- extern int impWriteTag(IMPImage *image, uint_t tagname, int length,
- void *buffer);
-
- /* Misc row operations */
-
- extern void impPackRow(uchar_t *dptr, short *sptr, int n);
- extern void impUnpackRow(short *dptr, uchar_t *sptr, int n);
-
- /* Row math functions */
- extern void impZeroRow(short *dptr, int n);
- extern void impInitRow(short *dptr, int val, int n);
- extern void impCopyRow(short *dptr, short *sptr, int n);
- extern void impSAddRow(short *dptr, short *sptr, int val, int n);
- extern void impVAddRow(short *dptr, short *sptr1, short *sptr2, int n);
- extern void impSSubRow(short *dptr, short *sptr, int val, int n);
- extern void impVSubRow(short *dptr, short *sptr1, short *sptr2, int n);
- extern void impSMulRow(short *dptr, short *sptr, int val, int n);
- extern void impSDivRow(short *dptr, short *sptr, int val, int n);
- extern void impClampRow(short *dptr, short *sptr, int lov, int hiv, int n);
-
- /* Color conversion functions */
- /* W */
- extern void impRGBtoW(short *rbuf, short *gbuf, short *bbuf,
- short *wbuf, int n);
- extern void impWtoRGB(short *wbuf, short *rbuf, short *gbuf, short *bbuf,
- int n);
- /* K */
- extern void impRGBtoK(short *rbuf, short *gbuf, short *bbuf,
- short *kbuf, short unity, int n);
- extern void impKtoRGB(short *kbuf, short *rbuf, short *gbuf, short *bbuf,
- short unity, int n);
- /* CMY */
- extern void impRGBtoCMY(short *rbuf, short *gbuf, short *bbuf,
- short *cbuf, short *mbuf, short *ybuf,
- short unity, int n);
- extern void impCMYtoRGB(short *cbuf, short *mbuf, short *ybuf,
- short *rbuf, short *gbuf, short *bbuf,
- short unity, int n);
- /* YIQ */
- extern void impRGBtoYIQ(short *rbuf, short *gbuf, short *bbuf,
- short *ybuf, short *ibuf, short *qbuf,
- int n);
- extern void impYIQtoRGB(short *ybuf, short *ibuf, short *qbuf,
- short *rbuf, short *gbuf, short *bbuf,
- int n);
- /* YUV */
- extern void impRGBtoYUV(short *rbuf, short *gbuf, short *bbuf,
- short *ybuf, short *ubuf, short *vbuf,
- int n);
- extern void impYUVtoRGB(short *ybuf, short *ubuf, short *vbuf,
- short *rbuf, short *gbuf, short *bbuf,
- int n);
- /* YCbCr (CCIR 601) */
- extern void impRGBtoYCbCr(short *rbuf, short *gbuf, short *bbuf,
- short *ybuf, short *cbbuf, short *crbuf,
- int n);
- extern void impYCbCrtoRGB(short *ybuf, short *cbbuf, short *crbuf,
- short *rbuf, short *gbuf, short *bbuf,
- int n);
- /* CMYK (optional transfer func, undercolor removal and K gen) */
- extern void impRGBtoCMYK(short *rbuf, short *gbuf, short *bbuf,
- short *cbuf, short *mbuf, short *ybug, short *kbuf,
- short unity, int n);
- extern void impRGBtoDevCMYK(short *rbuf, short *gbuf, short *bbuf,
- short *cbuf, short *mbuf, short *ybug, short *kbuf,
- IMPUCRFunc ucr, IMPBGFunc bg, short unity, int n);
- extern void impCMYKtoRGB(short *cbuf, short *mbuf, short *ybuf,
- short *kbuf, short *rbuf, short *gbug, short *bbuf,
- short unity, int n);
- /* HSV */
- extern void impRGBtoHSV(short *rbuf, short *gbuf, short *bbuf,
- float *hbuf, float *sbuf, float *vbuf, int n);
- extern void impHSVtoRGB(float *hbuf, float *sbuf, float *vbuf,
- short *rbuf, short *gbuf, short *bbuf, int n);
- /* HLS */
- extern void impRGBtoHLS(short *rbuf, short *gbuf, short *bbuf,
- float *hbuf, float *lbuf, float *sbuf,
- short unity, int n);
- extern void impHLStoRGB(float *hbuf, float *lbuf, float *sbuf,
- short *rbuf, short *gbuf, short *bbuf,
- short unity, int n);
-
- /* Row zoom functions */
- extern IMPZoom* impCreateZoom(ushort_t srcXSize, ushort_t srcYSize,
- ushort_t dstXSize, ushort_t dstYSize,
- long min, long max,
- IMPReadRowFunc readRowFunc, int numChannels,
- IMPFilterType filterType, float blurFactor);
- extern void impDestroyZoom(IMPZoom *zoom);
- extern void impResetZoom(IMPZoom *zoom);
- extern int impZoomRow(IMPZoom *zoom, short *buffer, ushort_t row,
- void *clientData);
- #ifdef __cplusplus
- }
- #endif
-
-
- #endif /* !__IMP_IMP_H__ */
-
-